﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{

    public class JLTWB18TOTData : BaseFunction
    {
        
        public JLTWB18TOTData()
            : base()
        {

        }
        public JLTWB18TOTData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public double ROLLS = 0,BATCH = 0;

        public DataSet GetWB18TOT(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "WB18TOT";
            string ART = dwABPOS["ART"].ToString().Trim();
            string COLOR = dwABPOS["COLOR"].ToString().Trim();
            string MTR = dwABPOS["MTR"].ToString().Trim();
            string PVH = dwABPOS["PVH"].ToString().Trim();
            string LANG = dwABPOS["LANG"].ToString().Trim();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT VKPART,VKPFARBE,VKPMEEH,RATE,KDART,DES,SUM(MTR) AS MTR,SUM(YARD) AS YARD, "
                    + " SUM(1) AS ROLLNUM,DECODE(VKPMEEH,'YRD',SUM(YARD),'M  ',SUM(MTR)) AS QTY,REFERANCE,VKPLIART,VKPLIART2,VKPAUFKRS,VKPAUFLFD,VKPAUFPOS, "
                    + " DECODE(VKPMEEH,'YRD',SUM(BYARD),'M  ',SUM(BMTR)) AS BQTY, "
                    + " SUM(DECODE(WBBZENSUR,'1',0,'2',1)) AS BROLLNUM, "
                    + " ROUND(AVG(NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)),1) AS AVGRATE, "
                    + " ROUND(MIN(NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)),1) AS MINRATE, "
                    + " ROUND(MAX(NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)),1) AS MAXRATE, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)<=10  "
                    + " AND NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>=0 THEN 1 END)) AS ROLLNUM1, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)<=10  "
                    + " AND NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>=0 THEN  "
                    + " DECODE(VKPMEEH,'YRD',YARD,'M  ',MTR) END)) AS ROLLQTY1, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)<=15  "
                    + " AND NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>10 THEN 1 END)) AS ROLLNUM2, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)<=15  "
                    + " AND NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>10 THEN  "
                    + " DECODE(VKPMEEH,'YRD',YARD,'M  ',MTR) END)) AS ROLLQTY2, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)<=20  "
                    + " AND NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>15 THEN 1 END)) AS ROLLNUM3, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)<=20  "
                    + " AND NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>15 THEN  "
                    + " DECODE(VKPMEEH,'YRD',YARD,'M  ',MTR) END)) AS ROLLQTY3, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)<=30  "
                    + " AND NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>20 THEN 1 END)) AS ROLLNUM4, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)<=30  "
                    + " AND NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>20 THEN  "
                    + " DECODE(VKPMEEH,'YRD',YARD,'M  ',MTR) END)) AS ROLLQTY4, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>30 THEN 1 END)) AS ROLLNUM5, "
                    + " SUM((CASE WHEN NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0)>30 THEN DECODE(VKPMEEH,'YRD',YARD,'M  ',MTR) END)) AS ROLLQTY5,'' as RESULT  "
                    + " FROM ( "
                    + " select distinct a.vkpart,a.vkpfarbe,a.vkpmeeh,a.vkpmeehfkt*0.000001 as rate,D.WBBSTKNR, "
                    + " TRIM(c.vakbkdartnr)||TRIM(c.vakbkdartbez)||TRIM(c.vakbkdfarbnr) as kdart,D.WBBZENSUR, "
                    + " (SELECT TRIM(T2.TXTKTEXT) FROM TXTIND T1,TXTKON T2 "
                    + " WHERE TXTITXTART = 'VAD' AND T1.TXTIMANDANT = T2.TXTKMANDANT "
                    + " AND T1.TXTIPIND = T2.TXTKPIND AND TRIM(T1.TXTISIND) = trim(b.vaakoll||b.vaaart)) as des, "
                    + " ROUND(d.wbbistklg*0.001,1) as mtr,round(d.wbbistklg*0.001/0.9144,1) as yard, "
                    + " (SELECT sum(DECODE(SUBSTR(X.WBFFSCHL,3,1),'A',1,'B',2,'C',3,'D',4)) "
                    + "  FROM WBFEHL X WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS AND D.wbbistklg>=X.WBFLGVON "
                    + " AND X.WBFVERSION='1' AND x.wbffschl<'900')AS dq, "
                    + " (SELECT round(avg(WBFBRTVON*0.001),1) FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.WBFBRTVON>40000) as avgwid, "
                    + " DECODE(D.WBBZENSUR,'2',ROUND(d.wbbistklg*0.001,1)) AS BMTR, "
                    + " DECODE(D.WBBZENSUR,'2',ROUND(d.wbbistklg/0.9144*0.001,1)) AS BYARD, "
                    + " (select STRAGG1(TRIM(T2.TXTKTEXT)) "
                    + " from txtind t1,txtkon t2 "
                    + " where t1.txtimandant = t2.txtkmandant "
                    + " and t1.txtipind = t2.txtkpind "
                    + " and t1.txtitxtart = 'VKT' "
                    + " AND TRIM(T1.TXTISIND) = A.VKPAUFKRS||A.VKPAUFLFD||'000LIEF' "
                    + " AND T2.TXTKPOS IN ('40','50')) AS REFERANCE,NVL(trim(VKPLIART),0) AS VKPLIART,NVL(trim(VKPLIART2),0) AS VKPLIART2,VKPAUFKRS,VKPAUFLFD,VKPAUFPOS "
                    + " from vkpos a,vaart b,vakdbez c,wbbst d "
                    + " where a.vkpmandant = b.vaamandant and a.vkpkoll = b.vaakoll "
                    + " and a.vkpart = b.vaaart and a.vkpmandant = c.vakbmandant(+) "
                    + " and a.vkpkoll = c.vakbkoll(+) and a.vkpart = c.vakbart(+) "
                    + " and a.vkpfarbe = c.vakbfarbe(+) and a.vkpkundnr = c.vakbkundnr(+) "
                    + " and b.vaamandant = d.wbbmandant and b.vaadart = d.wbbart  "
                    + " and a.vkpfarbe = d.wbbfarbe "
                    + " and a.vkpsa<>'AJ' and d.wbbwakz = 'F' and d.wbblb IN ('CP','CW','KO')  "
                    + " and d.wbbistklg>"+MTR+" and a.vkpmandant = '00' AND TRIM(a.vkpart)= '" + ART + "' AND TRIM(a.vkpfarbe)='" + COLOR + "' "
                    + " ) GROUP BY VKPART,VKPFARBE,VKPMEEH,RATE,KDART,DES,REFERANCE,VKPLIART,VKPLIART2,VKPAUFKRS,VKPAUFLFD,VKPAUFPOS "
                    ;
                
                Result = Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    double avgwidth = 0;
                    byte[] b;
                    string value;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["DES"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["DES"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["KDART"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["KDART"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["REFERANCE"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["REFERANCE"] = value;
                        ROLLS = System.Convert.ToDouble(dw["VKPLIART"].ToString().Trim());
                        BATCH = System.Convert.ToDouble(dw["VKPLIART2"].ToString().Trim());
                        avgwidth = System.Convert.ToDouble(dw["AVGRATE"].ToString().Trim());
                        if (BATCH > 0)
                        {
                            if (avgwidth <= BATCH)
                            {
                                if (LANG == "V")
                                {
                                    dw["RESULT"] = "合格";
                                }
                                else
                                {
                                    dw["RESULT"] = "Pass";
                                }
                            }
                            else
                            {
                                if (LANG == "V")
                                {
                                    dw["RESULT"] = "不合格";
                                }
                                else
                                {
                                    dw["RESULT"] = "Rejection";
                                }
                            }
                            
                        }
                    }
                }
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public DataSet GetWB18(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "WB18";
            string ART = dwABPOS["ART"].ToString().Trim();
            string COLOR = dwABPOS["COLOR"].ToString().Trim();
            string LANG = dwABPOS["LANG"].ToString().Trim();
            string MTR = dwABPOS["MTR"].ToString().Trim();
            string PVH = dwABPOS["PVH"].ToString().Trim();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT VKPART,VKPFARBE,VKPMEEH,WBBEINDAT,ROLL,WBBSTKNR,MTR,YARD,WBBTAX, "
                    + " WBBDPART,COL1,COL2,COL3,HAND,SKEW,SKEWMAX,SKEWMIN,BOW,BOWMAX,BOWMIN,NVL(DQ,0)AS DQ,NVL(ROUND(decode('" + PVH + "','J',NVL(DQ,0)/YARD*100,DECODE(NVL(AVGWID,0),0,0, "
                    + " NVL(DQ,0)*36/AVGWID/YARD*100)),1),0) AS RATE, "
                    + " WIDTH,WIDTHMAX,WIDTHMIN,AVGWID,AQTY,BQTY,DEFECT,'' AS X1,'' AS X2,'' AS X3,'' AS X4,'' AS X5,'' AS X6, "
                    + " '' AS X7,'' AS X8,'' AS X9,'' AS X10,'' AS X11,'' AS X12,'' AS X13,'' AS X14,'' AS X15, "
                    + " '' AS X16,'' AS X17,'' AS X18,'' AS X19,'' AS X20 "
                    + " FROM ( "
                    + " select distinct a.vkpart,a.vkpfarbe,a.vkpmeeh, "
                    + " d.wbbeindat,to_number(d.wbbpacknr) as roll,D.WBBSTKNR,to_char(ROUND(d.wbbistklg*0.001,1),'FM9999999.0') as mtr, "
                    + " to_char(round(d.wbbistklg*0.001/0.9144,1),'FM9999999.0') as yard,d.wbbtax,d.wbbdpart, "
                    + " d.WBBRSFSCHL as col1,d.WBBVEFSCHL as col2,d.WBBVSFSCHL as col3,d.WBBREFSCHL as hand, "
                    //+ " decode(d.wbbausffrb,100,'',d.wbbausffrb*0.1) as skew, "
                    + " (SELECT STRAGG(TO_CHAR(WBFBRTVON*0.001,'FM9999990.0')) FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.wbffschl='94 ') as SKEW, "
                    + " (SELECT TO_CHAR(max(WBFBRTVON*0.001),'FM9999990.0') FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.wbffschl='94 ') as SKEWMAX, "
                    + " (SELECT TO_CHAR(min(WBFBRTVON*0.001),'FM9999990.0') FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.wbffschl='94 ') as SKEWMIN, "
                    //+ " decode(d.wbbausfqual,100,'',d.wbbausfqual*0.1) as BOW, "
                    + " (SELECT STRAGG(TO_CHAR(WBFBRTVON*0.001,'FM9999990.0')) FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.wbffschl='95 ') as BOW, "
                    + " (SELECT TO_CHAR(max(WBFBRTVON*0.001),'FM9999990.0') FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.wbffschl='95 ') as BOWMAX, "
                    + " (SELECT TO_CHAR(min(WBFBRTVON*0.001),'FM9999990.0') FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.wbffschl='95 ') as BOWMIN, "
                    + " (SELECT sum(DECODE(SUBSTR(X.WBFFSCHL,3,1),'A',1,'B',2,'C',3,'D',4)) "
                    + "  FROM WBFEHL X WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS AND D.wbbistklg>=X.WBFLGVON "
                    + " AND X.WBFVERSION='1' AND x.wbffschl<'900')AS dq, "
                    + " (SELECT STRAGG(WBFBRTVON*0.001) FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.WBFBRTVON>40000) as WIDTH, "
                    + " (SELECT to_char(MAX(WBFBRTVON*0.001),'FM9999990.0') FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.WBFBRTVON>40000) as WIDTHMAX, "
                    + " (SELECT to_char(MIN(WBFBRTVON*0.001),'FM9999990.0') FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.WBFBRTVON>40000) as WIDTHMIN, "
                    + " (SELECT round(avg(WBFBRTVON*0.001),1) FROM WBFEHL X  "
                    + " WHERE d.wbbmandant= X.WBFMANDANT AND d.wbbrwkrs = X.WBFRWKRS "
                    + " AND d.wbbrwlfd = X.WBFRWLFD AND d.wbbpos = X.WBFRWPOS "
                    + " AND X.WBFVERSION='1' AND X.WBFBRTVON>40000) as avgwid, "
                    + " DECODE(D.WBBZENSUR,'1','Y') AS AQTY,DECODE(D.WBBZENSUR,'2','Y') AS BQTY, "
                    + " (SELECT STRAGG(A||'-'||B) FROM ( "
                    + " select count(1) AS A,(case when '"+LANG+"'='V' THEN TRIM(SUBSTR(y.SDDATEN, 2, 20)) "
                    + " WHEN '" + LANG + "'='E' THEN trim(substr(Y.sddaten,70,40)) END) AS B, "
                    + " X.WBFMANDANT,X.WBFRWKRS,X.WBFRWLFD,X.WBFRWPOS "
                    + " from wbfehl x,sddat y "
                    + " where x.wbfmandant||x.wbffschl =SUBSTR(y.SDKEY,1,5) and y.sdsa = '0267' "
                    + " and X.WBFVERSION='1' and x.wbffschl<'900'  "
                    + " group by y.SDDATEN,X.WBFMANDANT,X.WBFRWKRS,X.WBFRWLFD,X.WBFRWPOS  "
                    + " ORDER BY A DESC)T "
                    + " WHERE T.WBFMANDANT = D.WBBMANDANT AND T.WBFRWKRS = D.WBBRWKRS "
                    + " AND T.WBFRWLFD= D.WBBRWLFD AND T.WBFRWPOS = D.WBBPOS)||'.'|| (SELECT STRAGG(TRIM(T2.TXTKTEXT)) "
                    + " FROM TXTIND T1,TXTKON T2 "
                    + " WHERE T1.TXTIMANDANT = T2.TXTKMANDANT AND T1.TXTIPIND = T2.TXTKPIND "
                    + " AND T1.TXTIMANDANT= D.WBBMANDANT AND T1.TXTITXTART = 'WBS' "
                    + " AND T1.TXTISIND LIKE D.WBBRWKRS||D.WBBRWLFD||D.WBBPOS||'%') AS DEFECT "
                    + " from vkpos a,vaart b,wbbst d "
                    + " where a.vkpmandant = b.vaamandant and a.vkpkoll = b.vaakoll "
                    + " and a.vkpart = b.vaaart and b.vaamandant = d.wbbmandant  "
                    + " and b.vaadart = d.wbbart and a.vkpfarbe = d.wbbfarbe "
                    + " and a.vkpsa<>'AJ' and d.wbbwakz = 'F' and d.wbblb IN ('CP','CW','KO')  "
                    + " and d.wbbistklg>"+MTR+" and a.vkpmandant = '00' AND TRIM(a.vkpart)= '" + ART + "' AND TRIM(a.vkpfarbe)='" + COLOR + "' "
                    + " ) order by ROLL " 
                    ;

                Result = Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    byte[] b;
                    string value,aqty;
                    double rate=0;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["DEFECT"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["DEFECT"] = value;
                        rate = System.Convert.ToDouble(dw["RATE"].ToString().Trim());
                        aqty = dw["AQTY"].ToString().Trim();
                        if(aqty == "Y")
                        { 
                            if(LANG=="V")
                            {
                                dw["AQTY"] = "合格";
                            }else
                            {
                                dw["AQTY"] = "Pass";
                            }
                            
                        }
                        if (ROLLS > 0)
                        {
                            if (rate <= ROLLS)
                            {
                                if (LANG == "V")
                                {
                                    dw["AQTY"] = "合格";
                                }
                                else
                                {
                                    dw["AQTY"] = "Pass";
                                }
                            }
                            else
                            {
                                if (LANG == "V")
                                {
                                    dw["AQTY"] = "不合格";
                                }
                                else
                                {
                                    dw["AQTY"] = "Rejection";
                                }
                            }
                        }
                    }
                }
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }       
        public DataSet BuildJLTWB18TOTData(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetWB18TOT(dwUI);
                setReturn.Merge(setResult);
                setResult = GetWB18(dwUI);
                setReturn.Merge(setResult); 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}